<template>
  <div class="avue-top">
    <div class="top-bar__left">
      <div class="avue-breadcrumb"
           :class="[{ 'avue-breadcrumb--active': isCollapse }]"
           v-if="setting.collapse&&!isHorizontal">
        <i class="icon-navicon"
           @click="setCollapse"></i>
      </div>
    </div>
    <div class="top-bar__title">
      <top-menu ref="topMenu"></top-menu>
      <top-search class="top-bar__item" v-if="setting.search"></top-search>
    </div>
    <div class="top-bar__right">
      <div v-if="setting.sysNotice"
           class="top-bar__item">
        <top-notice></top-notice>
      </div>
      <div v-if="setting.lock"
           class="top-bar__item">
        <top-lock></top-lock>
      </div>
      <div v-if="setting.theme"
           class="top-bar__item">
        <top-theme></top-theme>
      </div>
      <div class="top-bar__item">
        <top-lang></top-lang>
      </div>
      <div class="top-bar__item"
           v-if="setting.fullscren">
        <top-full></top-full>
      </div>
      <div class="top-bar__item"
           v-if="setting.debug">
        <top-logs></top-logs>
      </div>
      <div class="top-user">
        <img class="top-bar__img"
             :src="userInfo.avatar">
        <el-dropdown>
          <span class="el-dropdown-link" style="cursor: pointer">
            {{ userInfo.userFinalName }}
          </span>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item>
                <router-link to="/">{{ $t('navbar.dashboard') }}</router-link>
              </el-dropdown-item>
              <el-dropdown-item>
                <router-link to="/info/index">{{ $t('navbar.userinfo') }}</router-link>
              </el-dropdown-item>
              <el-dropdown-item>
                <router-link to="/info/setting">{{ $t('navbar.setting') }}</router-link>
              </el-dropdown-item>
              <el-dropdown-item @click="$refs.switchLoginUserDialog.show()">

               {{ $t('navbar.switchLoginUser') }}
              </el-dropdown-item>
              <el-dropdown-item @click="logout"
                                divided>{{ $t('navbar.logOut') }}
              </el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
        <top-setting></top-setting>
        <switch-login-user-dialog ref="switchLoginUserDialog"></switch-login-user-dialog>
      </div>
    </div>
  </div>
</template>
<script>
import {mapState} from "pinia";
import topLock from "./top-lock.vue";
import topMenu from "./top-menu.vue";
import topSearch from "./top-search.vue";
import topTheme from "./top-theme.vue";
import topLogs from "./top-logs.vue";
import topLang from "./top-lang.vue";
import topFull from "./top-full.vue";
import topSetting from "../setting.vue";
import useCommonStore from "@/stores/useCommonStore";
import useRouterStore from "@/stores/useRouterStore";
import useLogStore from "@/stores/useLogStore";
import useUserStore from "@/stores/useUserStore";
import TopNotice from "@/page/index/top/top-notice.vue";
import SwitchLoginUserDialog from "@/page/index/top/components/switchLoginUserDialog.vue";

export default {
  components: {
    SwitchLoginUserDialog,
    TopNotice,
    topLock,
    topMenu,
    topSearch,
    topTheme,
    topLogs,
    topLang,
    topFull,
    topSetting
  },
  name: "top",
  filters: {},

  computed: {
    ...mapState(useCommonStore, ["setting", "isCollapse", "isHorizontal"]),
    ...mapState(useRouterStore, ["tagWel", "tagList", "tag"]),
    ...mapState(useLogStore, ["logsLen", "logsFlag"]),
    ...mapState(useUserStore, ["userInfo"])
  },
  data() {
    return {};
  },

  created() {
  },
  methods: {
    setCollapse() {
      const commonStore = useCommonStore()
      commonStore.toggleCollapse();
    },
    logout() {
      this.$confirm(this.$t("logoutTip"), this.$t("tip"), {
        confirmButtonText: this.$t("submitText"),
        cancelButtonText: this.$t("cancelText"),
        type: "warning"
      }).then(() => {

        useUserStore().LogOut().then(() => {
          this.$router.push({path: "/login"});
        });
      });
    }
  }
};
</script>

<style lang="scss" scoped>
</style>
